package pers.xuyong.code.annotation;

import pers.xuyong.code.lang.classloader.NetworkClassLoader;

/**
 * 主入口
 *
 * @author billymac
 * @version 1.0
 * @date 17/7/10  下午2:38
 * @since JDK1.8
 */
public class Main {

    public static void main(String[] args) throws ClassNotFoundException {
//        EnumClass.SingleEnum.display();
//        MyThread t1 = new MyThread();
//        MyThread t2 = new MyThread();
//        MyThread t3 = new MyThread();
//        t1.start();
//        t2.start();
//        t3.start();
//        ExecutorService executorService = Executors.newFixedThreadPool(5);
//        ExecutorService executorService = Executors.newCachedThreadPool();
//        ExecutorService executorService = Executors.newFixedThreadPool(5);
//        for (int i = 0; i < 5; i++) {
//            executorService.submit(new ExecuteRunnable());
//            System.out.println("==================" + i + "===================");
//        }
//        executorService.shutdown();

//        List<Future<String>> futures = new ArrayList<Future<String>>();
//        for (int i = 0; i < 10; i++) {
//            futures.add(executorService.submit(new ExecuteCallable(i)));
//        }
//
//        for (Future<String> future : futures) {
//            while(!future.isDone());
//            try {
//                System.out.println(future.get());
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            } catch (ExecutionException e) {
//                e.printStackTrace();
//            } finally {
//                executorService.shutdown();
//            }
//        }

//        try {
//            Class myAnnotationClass = Class.forName("pers.xuyong.code.annotation.MyAnnotationClass");
//            MyAnnotationClass obj = (MyAnnotationClass) myAnnotationClass.newInstance();
//            Field annotationField = myAnnotationClass.getField("annotationField");
//            MyAnnotation annotation =annotationField.getAnnotation(MyAnnotation.class);
//            int val = annotation.val();
//            annotationField.setInt(obj, val);
//
//            System.out.println("pers.xuyong.code.annotation.MyAnnotationClass : " + obj.annotationField);
//        } catch (ClassNotFoundException e) {
//            e.printStackTrace();
//        } catch (NoSuchFieldException e) {
//            e.printStackTrace();
//        } catch (InstantiationException e) {
//            e.printStackTrace();
//        } catch (IllegalAccessException e) {
//            e.printStackTrace();
//        }

//        System.out.println("Self Classloader : " + Main.class.getClassLoader().toString());
//        System.out.println("Parent Classloader : " + Main.class.getClassLoader().getParent().toString());
//        System.out.println("Top Parent Classloader : " + Main.class.getClassLoader().getParent().getParent().toString());

//        System.out.println("Self Classloader : " + ClassLoader.class.getClassLoader());
//        System.out.println("Parent Classloader : " + Main.class.getClassLoader().getParent().toString());
//        System.out.println("Top Parent Classloader : " + Main.class.getClassLoader().getParent().getParent().toString());

//        URL[] urLs = Launcher.getBootstrapClassPath().getURLs();
//        for (int i = 0; i < urLs.length; i++) {
//            System.out.println(urLs[i].toString());
//        }
//
//        System.out.println();
//        System.out.println();
//        System.out.println(System.getProperty("sun.boot.class.path"));
//        DefineClassLoader defineClassloader = new DefineClassLoader();
//        Class aClass = defineClassloader.loadClass("pers.xuyong.code.lang.thread.Context");
//        System.out.println(aClass.getClassLoader());
        NetworkClassLoader networkClassLoader = new NetworkClassLoader("http://localhost:8080");
        Class<?> everythingIsObject = networkClassLoader.loadClass("EverythingIsObject");
        System.out.println(everythingIsObject.getClassLoader());


    }
}
